package com.gbr.presentation.recordingarea.impl;

import java.awt.Rectangle;

import com.gbr.application.action.ShowRecordingAreaAction;
import com.gbr.presentation.recordingarea.IRecordingAreaPresentation;
import com.ng.framework.gui.presentation.AbstractPresentationModel;
import com.ng.framework.service.action.IActionListener;
import com.ng.framework.service.log.LogLevel;

public class RecordingAreaPresentation extends AbstractPresentationModel implements IRecordingAreaPresentation {
    private RecordingAreaActionListener selectAreaListener = new RecordingAreaActionListener();
    private Rectangle                   rect               = null;

    @Override
    protected void activateComponent() {
        logService.log(getClass(), LogLevel.TRACE, "Activating");
        actionService.addListener(ShowRecordingAreaAction.class, selectAreaListener);
    }

    @Override
    protected void deactivateComponent() {
        logService.log(getClass(), LogLevel.TRACE, "Dectivating");
        actionService.removeListener(ShowRecordingAreaAction.class, selectAreaListener);
    }

    @Override
    public Rectangle getRecordingRect() {
        return rect;
    }

    class RecordingAreaActionListener implements IActionListener<ShowRecordingAreaAction> {
        @Override
        public void actionPerformed(final ShowRecordingAreaAction action) {
            rect = action.getRect();

            new Thread(new Runnable() {
                @Override
                public void run() {
                    firePropertyChange(IRecordingAreaPresentation.ACTIVATE, action.isShow(), null);
                }
            }).start();
        }
    }
}
